package com.itqf.quartz;

import com.itqf.job.TimeJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

/**
 * projectName: logandquartzgp8
 *
 * @author: 赵伟风
 * time: 2021/8/10 16:12
 * description:10秒后开始 每一秒执行一次！执行5次
 */
public class SimpleJob2 {


    public static void main(String[] args) throws SchedulerException {

        //1.创建jobDetail
        JobDetail build = JobBuilder.newJob(TimeJob.class).build();

        //2.创建simpleTrigger
        // withRepeatCount 真实的次数等于指定的次数+1
        Date start = DateBuilder.futureDate(10, DateBuilder.IntervalUnit.SECOND);
        SimpleTrigger simpleTrigger = TriggerBuilder.newTrigger().startAt(start)
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).withRepeatCount(4)).build();

        //3.创建调度器并且执行
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = stdSchedulerFactory.getScheduler();

        scheduler.scheduleJob(build, simpleTrigger);

        scheduler.start();

    }

}
